package com.jrx.anytxn.customer.service;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.customer.bean.CreditApprovalBean;
import com.jrx.anytxn.customer.dto.creditinfo.AdjustLimitRecordRes;
import com.jrx.anytxn.customer.dto.creditinfo.CreditActiveReq;
import com.jrx.anytxn.customer.dto.creditinfo.CreditInfoTree;
import com.jrx.anytxn.customer.dto.customer.CustomerLimitInfoRes;
import com.jrx.anytxn.customer.dto.customer.CustomerRenewalReq;
import com.jrx.anytxn.customer.dto.customer.CustomerRenewalRes;
import com.jrx.anytxn.customer.entity.CmCustomerLimitInfo;
import com.jrx.anytxn.customer.entity.CmLimitAdjustLog;
import com.jrx.anytxn.customer.entity.CmLimitChangeLog;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 客户额度表管理接口
 *
 * @author Qingyao Xing
 * @date 2019/7/18 17:02
 */
public interface ICustomerLimitInfoService {

    /**
     * 获取客户额度信息  修改返回值
     *
     * @param customerId     客户ID
     * @param organizationId 机构ID
     * @param channel        渠道号
     * @param productId      产品ID
     * @param contractNumber 合同号
     * @param loanAmount     贷款金额
     * @param tenantId       租户id
     * @return com.jrx.anytxn.customer.dto.customer.CustomerLimitInfoRes
     * @author fan.yang
     * date: 2019/9/24 0024 下午 15:48
     */
    CmCustomerLimitInfo getCustomerLimitInfo(String customerId, String organizationId, String channel,
                                             String productId, String contractNumber, BigDecimal loanAmount,
                                             String tenantId) throws TxnBizException;

    /**
     * 校验客户状态和可用额度是否满足
     * @author fan.yang
     * date: 2019/10/24 0024 上午 10:17
     * @param info 客户额度信息
     * @param loanAmount 贷款金额
     * @param businessDate 业务日期
     */
    void verifyCustomer(CmCustomerLimitInfo info, BigDecimal loanAmount, Date businessDate) throws TxnBizException;


    /**
     * 更新客户额度信息  修改入参类型
     *
     * @param cmCustomerLimitInfo 客户额度请求实体
     * @param loanAmount          贷款金额
     * @param userId              用户ID
     * @return void
     * @author fan.yang
     * date: 2019/10/21 0021 下午 15:29
     */
    void modifyCustomerLimit(CmCustomerLimitInfo cmCustomerLimitInfo, BigDecimal loanAmount, String userId) throws TxnBizException;


    /**
     * 根据机构号和客户id，渠道获取客户所有授权的额度集合
     * @param organizationId 机构号
     * @param customerId     客户id
     * @param tenantId       租户id
     * @return java.util.List<CmCustomerLimitInfo>
     * @author Qingyao Xing
     * @date 2019/8/5 15:48
     */
    List<CmCustomerLimitInfo> selectCusLimitListByCustId(String organizationId, String customerId, String tenantId);

    /**
     * 授信管理
     *
     * @param bean 授信请求数据逻辑处理后的map集合
     * @author Qingyao Xing
     * @date 2019/8/5 17:01
     */
    void registerCustomerLimitInfo(CreditApprovalBean bean) throws Exception;

    /**
     * 客户额度调整
     *
     * @param list 客户额度实体集合
     * @author Qingyao Xing
     * @date 2019/8/7 14:06
     */
    void modifyCustomerLimitList(List<CmCustomerLimitInfo> list,List<CmLimitAdjustLog> limitAdjustLogList) throws TxnException;

    /**
     * 获取对应状态，渠道，客户的节点集合的客户额度授信集合
     *
     * @param channel      渠道
     * @param customerId      客户id
     * @param organizationId 机构号
     * @param limitId        额度节点
     * @param tenantId       租户id
     * @return java.util.List<CmCustomerLimitInfo> 客户额度查询的响应实体集合
     * @author Qingyao Xing
     * @date 2019/8/15 18:14
     */
    List<CmCustomerLimitInfo> getCusLimitByLimtIdAndCusIdAndOrgId(List<String> limitId, String organizationId, String channel, String customerId , String tenantId,String status) throws TxnException;

    /**
     * 获取客户额度的额度树
     *
     * @param organizationId 机构号
     * @param customerId     客户id
     * @param status         状态
     * @param tenantId       租户id
     * @return java.util.List<com.jrx.anytxn.customer.dto.creditinfo.CreditInfoTree> 客户额度树查询响应集合
     * @author Qingyao Xing
     * @date 2019/8/8 13:44
     */
    List<CreditInfoTree> getCusLimitTree(String organizationId, String customerId, String status, String tenantId) throws TxnException;

    /**
     * 额度冻结/解冻
     *
     * @param cmCustomerLimitInfoList 客户额度实体集合
     * @author Qingyao Xing
     * @date 2019/8/8 20:34
     */
    void modifyCustomerLimitStatus(List<CmCustomerLimitInfo> cmCustomerLimitInfoList ) throws TxnException;

    /**
     * 客户额度列表分页查询
     *
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return java.util.ArrayList<com.jrx.anytxn.customer.dto.customer.CustomerLimitInfoRes> 客户额度信息集合
     * @author Liy
     * @date 2019/9/27 14:27
     */
    ArrayList<CustomerLimitInfoRes> getLimitList( String customerId, String tenantId);
   /**
    * 还款是修改客户额度
    * @param customerId 客户id
    * @param organizationId 机构号
    * @param channel 渠道
    * @param productId 产品id
    * @param payAmount 还款金额
    * @param tenantId 租户id
    * @author Qingyao Xing
    * @date 2019/10/22 10:56
    */
   void  modifyCustomerLimitByPayment (String tenantId,String customerId, String organizationId, String channel, String productId, BigDecimal payAmount) throws TxnBizException;


    /**
     * 根据租户id和客户id查询相关调额记录
     * @author fan.yang
     * date: 2020/4/10 0010 上午 10:34
     * @param tenantId 租户id
     * @param customerId 客户id
     * @return java.util.ArrayList<com.jrx.anytxn.transaction.dto.manuallyTransaction.AdjustLimitRecordRes>
     */
    ArrayList<AdjustLimitRecordRes> getAdjustLimitRecord(String tenantId, String customerId,String channel);

    /**
     * 根据机构id,渠道号,客户编号,额度编号,租户号查询单条客户额度信息
     * @param organizationId
     * @param channel
     * @param customerId
     * @param limitId
     * @param tenantId
     * @return
     */
    CustomerLimitInfoRes selectCustomerLimitInfo(String organizationId,String channel,String customerId,String limitId,String tenantId) throws TxnException;

    /**
     * 取消授信修改客户额度信息
     *
     * @param cmCustomerLimitInfo 客户额度节点信息
     * @throws TxnException
     */
    void cancelCreditModifyCustomerLimitInfo(CmCustomerLimitInfo cmCustomerLimitInfo) throws TxnException;

    /**
     * 恢复客户额度（所有额度类型都恢复）
     * @param tenantId
     * @param customerId
     * @param organizationId
     * @param channel
     * @param productId
     * @param amount
     * @throws TxnBizException
     */
    void modifyCustomerLimit(String tenantId, String customerId, String organizationId, String channel, String productId, BigDecimal amount,String contractNumber) throws TxnBizException;

    /**
     * 获取用户的授信信息-根据有效期排序（升序）
     *
     * @param customerId
     * @param tenantId
     * @param organizationId
     * @param limitIds
     * @return
     */
    List<CmCustomerLimitInfo> getCmCustomerLimitInfos(String customerId, String tenantId, String organizationId, List<String> limitIds);

    /**
     * 查询用户首次额度
     * @param tenantId
     * @param customerId
     * @param limitIds
     * @param status
     * @param etlEffectiveDate
     * @return
     */
    CmLimitAdjustLog queryFirstAdjustLog(String tenantId, String customerId, List<String> limitIds, String status, Date etlEffectiveDate);

    /**
     * 获取用户"首笔贷款额度信息"
     * @param tenantId
     * @param customerId
     * @param productIds
     * @return
     */
    CmLimitChangeLog queryFirstLimitChangeLog(String tenantId, String customerId, List<String> productIds);

    /**
     * 计算结清日期
     * @param tenantId
     * @param customerId
     * @param productIds
     * @param organizationId
     * @param businessDate
     * @return
     * @throws TxnBizException
     */
    String calculateSettleDate(String tenantId, String customerId, String productIds, String organizationId, Date businessDate) throws TxnBizException;

    /**
     * 客户续场景景判断
     * @param req
     * @return
     */
    CustomerRenewalRes customerSceneInfo(CustomerRenewalReq req) throws TxnBizException;


    /**
     * 获取用戶最新的综合额度生效日期
     * @param tenantId
     * @param customerId
     * @param productIds
     * @return
     */
    CmLimitChangeLog queryLatestEtlEffectDate(String tenantId, String customerId, List<String> productIds);

    /**
     * 获取客户某产品的额度变更记录
     * @param tenantId
     * @param customerId
     * @param productId
     * @return
     */
    List<CmLimitChangeLog> queryChangeLogs(String tenantId, String customerId, String productId);

    /**
     * 激活时更新授信合同号和额度编号
     * @param req
     */
    void updateEtlInfos(CreditActiveReq req) throws Exception;

    /**
     * 查询激活的产品ids
     * @param customerId
     * @param tenantId
     * @param productIds
     * @return
     * @throws Exception
     */
    List<String> getActiveProducts(String customerId, String tenantId, List<String> productIds) throws Exception;
}
